package com.vdf.sisconsolid.mail;


//File Name SendEmail.java

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendEmail
{
private static String from;
private static String password;

public static void main(String [] args)
{    
   // Recipient's email ID needs to be mentioned.
   String to = "visionpdg@gmail.com,sisconsolid@gmail.com,maguigal@hotmail.com";

   // Sender's email ID needs to be mentioned
   from = "sisconsolid@gmail.com";
   password = "consolidacion123";

//   // Assuming you are sending email from localhost
//   String host = "localhost";

   // Get system properties
   Properties properties = System.getProperties();

   // Setup mail server
   //properties.setProperty("mail.smtp.host", host);
   properties.put("mail.smtp.starttls.enable", "true"); 
   properties.put("mail.smtp.host", "smtp.gmail.com");
   properties.put("mail.smtp.user", from); // User name
   properties.put("mail.smtp.password", password); // password
   properties.put("mail.smtp.port", "587");
   properties.put("mail.smtp.auth", "true");

   // Get the default Session object.
   Session session = Session.getDefaultInstance(properties, 
		    new javax.mail.Authenticator(){
       protected PasswordAuthentication getPasswordAuthentication() {
           return new PasswordAuthentication(
        		   from, password);// Specify the Username and the PassWord
       }
});

   try{
      // Create a default MimeMessage object.
      MimeMessage message = new MimeMessage(session);

      // Set From: header field of the header.
      message.setFrom(new InternetAddress(from));

      // Set To: header field of the header.
      message.addRecipients(Message.RecipientType.TO, to);

      // Set Subject: header field
      message.setSubject("SECOND This is the Subject Line!");

      // Now set the actual message
      message.setText("SECOND This is actual message");

      // Send message
      Transport.send(message);
      System.out.println("Sent message successfully....");
   }catch (MessagingException mex) {
      mex.printStackTrace();
   }
}
}